<template>
  <div class="app-view">
    <div class="welcome-section">
      <img src="@/assets/images/layout-bg.png" alt="灵溪" class="logo">
      <div style="margin-top: -20px">
        <h1>灵溪</h1>
        <p class="subtitle">让人工智能融入您的工作流程</p>
      </div>
    </div>

    <div class="models-section">
      <div
        class="model-card"
        :class="{ 'disabled': !model.enabled }"
        v-for="model in models"
        :key="model.id"
        @click="selectModel(model)"
      >
        <div class="model-icon">
          <i :class="model.icon"></i>
        </div>
        <div class="model-info">
          <h3>{{ model.name }}</h3>
          <p>{{ model.description }}</p>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import {http} from "@/api";

export default {
  name: 'AppIndex',
  data() {
    return {
      models: [
        // {
        //   id: 'deepseek-v3',
        //   name: 'DeepSeekV3',
        //   description: '深度思考的AI助手',
        //   icon: 'el-icon-chat-dot-round',
        //   model: 'deepseek-v3',
        //   enabled: 1,
        //   path: '/conversation/chat'
        // },
        // {
        //   id: 'deepseek-r1',
        //   name: 'DeepSeekR1',
        //   description: '深度思考的AI助手',
        //   icon: 'el-icon-chat-dot-round',
        //   model: 'deepseek-r1',
        //   enabled: 1,
        //   path: '/conversation/chat'
        // },
        // {
        //   id: 'tongyi',
        //   name: '通义千问',
        //   description: '通义千问AI助手',
        //   icon: 'el-icon-chat-dot-round',
        //   model: 'qwen-plus',
        //   enabled: 1,
        //   path: '/conversation/chat'
        // },
        // {
        //   id: 'gpt-4',
        //   name: 'GPT-4',
        //   description: '更强大的AI对话能力',
        //   icon: 'el-icon-chat-line-round',
        //   model: 'gpt-4o',
        //   enabled: 1,
        //   path: '/conversation/chat'
        // },
        // {
        //   id: 'wanxiang',
        //   name: '通义万相',
        //   description: 'AI生成图片',
        //   icon: 'el-icon-picture',
        //   model: 'wanxiang',
        //   enabled: 1,
        //   path: '/conversation/wanxiang'
        // },
        // {
        //   id: 'mj',
        //   model: 'mj',
        //   name: 'MidJourney',
        //   description: '基于MidJourney的AI绘画助手',
        //   icon: 'el-icon-picture-outline',
        //   enabled: 1,
        //   path: '/conversation/mj'
        // }
      ]
    }
  },
  created() {
    console.log('this.$store.state.user.userInfo.id',this.$store.state.user.userInfo.id)
    http.model.userList({
      user_id: this.$store.state.user.userInfo.id
    }).then(res => {
      this.models = res.data
    })
  },
  methods: {
    selectModel(model) {
      if (!model.enabled) {
        this.$message.warning('该功能暂未开放，敬请期待');
        return;
      }
      if (model.model === 'mj' || model.model === 'wanxiang') {
        http.conversation.create(null, {
          user_id: this.$store.state.user.userInfo.id,
          title: '新会话',
          model: model.model,
          is_archived: 0
        }).then(res => {
          this.$router.push({
            path: model.path,
            query: {
              model: model.model,
              conversationId: res.data.id
            }
          });
        })
      } else {
        this.$router.push({
          path: model.path,
          query: {
            model: model.model
          }
        });
      }
    }
  }
}
</script>

<style lang="scss">
.app-view {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-bottom: 60px;
  padding: 20px;
}

.welcome-section {
  text-align: center;
  margin-bottom: 30px;
  margin-top: -40px;
  .logo {
    width: 70%;
    margin-bottom: -20px;
  }

  h1 {
    font-size: 32px;
    font-weight: 600;
    color: #1C1C28;
    margin-bottom: 12px;
  }

  .subtitle {
    font-size: 16px;
    color: #666;
  }
}

.models-section {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  width: 100%;
  max-width: 720px;
  padding: 0 32px;
  .model-card {
    background: #fff;
    border-radius: 12px;
    padding: 16px;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    background-color: rgba(24, 0, 72, 0.04);
    min-height: 128px;
    &:hover {
      transform: translateY(-2px);
      box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
    }
    .model-icon {
      width: 32px;
      height: 32px;
      border-radius: 10px;
      background: rgba(126, 76, 224, 0.1);
      display: flex;
      align-items: center;
      justify-content: center;

      i {
        font-size: 16px;
        color: #7E4CE0;
      }
    }

    .model-info {
      text-align: center;
      h3 {
        font-size: 16px;
        font-weight: 600;
        color: #1C1C28;
        margin-bottom: 4px;
      }

      p {
        font-size: 12px;
        color: #666;
        margin: 0;
        line-height: 1.4;
      }
    }
  }
  .model-card.disabled {
    opacity: 0.6;
    cursor: not-allowed;
    &:hover {
      transform: none;
      box-shadow: none;
    }
  }

  .model-card:last-child .model-icon {
    background-color: rgba(207, 139, 92, 0.13);
    i {
      color: rgba(207, 139, 92, 1);
    }
  }

}
</style>
